﻿using System;
using System.Web;
using System.Web.UI;
using CardLogistics.Model.Sys;
using System.Web.UI.WebControls;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;
using System.Data;
using Wuqi.Webdiyer;
using System.Collections;
using System.Reflection;
using DotNet.Kernel;
using System.Data.OracleClient;
using CardLogistics.DAL;
using System.Collections.Generic;
using System.IO;
using System.Data.OleDb;
using System.Web.Hosting;
using NPOI.HSSF.UserModel;

namespace CardLogistics.Web.Components
{
    /// <summary>
    /// 所有asp.net页的基类。
    /// </summary>
    public class BasePage : Page
    {
        /// <summary>
        /// 每页显示的条数
        /// </summary>
        public int WebPageSize = 10;
        /// <summary>
        /// 当前页
        /// </summary>
        public int WebPageIndex = 1;
        /// <summary>
        /// 系统初始化时的查询条件
        /// </summary>
        public string LoadStrWhere = " and 1<>1 ";

        bool requiresAuthentication = true;
        protected bool _EnsureFramePage = true;
        bool _allowCache = true;
        bool _registerScript = true;

        /// <summary>
        /// 是否是编辑操作
        /// </summary>
        public bool IsEdit
        {
            get;
            set;
        }
        /// <summary>
        /// 当菜单ID
        /// </summary>
        public string Mid
        {
            get;
            set;
        }
        #region 页面受保护的方法

        /// <summary>
        /// 重写OnInit方法，进行用户验证及设置缓存
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            if (requiresAuthentication)
            {
                if (!_allowCache)
                    Response.Cache.SetCacheability(HttpCacheability.NoCache);
                AuthCookie auCookie = new AuthCookie();
                AuthCookie auCookie2 = null;
                //如果用户未验证通过，则跳转
                if (!auCookie.IsAuthenticated)
                {
                    auCookie.GetLoggedUser();
                    auCookie2 = new AuthCookie();
                }
                if (auCookie2 != null && !auCookie2.IsAuthenticated)
                {
                    Response.Redirect(string.Format("{0}/login.aspx?returnUrl={1}", this.AppPath, Request.RawUrl));
                }

                if (GetUrlParam("type").ToLower() == "edit")
                {
                    if (FindControl("btn_Submit") != null)
                        ((FindControl("btn_Submit")) as Button).Text = "修改并提交";
                    if (FindControl("btn_Add") != null)
                        ((FindControl("btn_Add")) as Button).Text = "完成修改";
                    IsEdit = true;
                }
                if (!string.IsNullOrEmpty(GetUrlParam("mid")))
                    Mid = GetUrlParam("mid");
            }
            base.OnInit(e);
        }

        #endregion

        #region 页面属性

        public bool RegisterScript
        {
            get { return _registerScript; }
            set { _registerScript = value; }
        }
        /// <summary>
        /// 指示是否将当前页显示在框架页中
        /// </summary>
        internal bool EnsureRenderInFrame
        {
            get { return this._EnsureFramePage; }
            set { this._EnsureFramePage = value; }
        }

        /// <summary>
        /// 是否允许页面被缓存，对于需要认证的页面，禁止页面被缓存可以防止未被授权的用户在脱机状态下浏览被缓存起来的需要认证才能访问的页面
        /// </summary>
        internal bool AllowCache
        {
            get { return _allowCache; }
            set { _allowCache = value; }
        }


        /// <summary>
        /// 获取登录的用户对象
        /// </summary>
        public Sys_SysUserInfo LoggedUser
        {
            get
            {
                AuthCookie aCookie = new AuthCookie();
                string href = AppPath + "Login.aspx";
                if (aCookie.GetLoggedUser() == null)
                {
                    WriteJavaScript("top.opener=null;top.open('','_self');top.location.href='" + href + "'", true);
                    return null;
                }
                return aCookie.GetLoggedUser();
            }
        }

        /// <summary>
        /// 获取和设置该页面是否需要认证（只有经验证的用户才能访问）
        /// </summary>
        internal bool RequiresAuthentication
        {
            get { return requiresAuthentication; }
            set { requiresAuthentication = value; }
        }

        /// <summary>
        /// 获取应用程序根路径。
        /// </summary>
        public string AppPath
        {
            get { return Request.ApplicationPath; }
        }

        #endregion

        #region 页面公用方法

        public void ReturnListInfo()
        {
            Response.Redirect("ListInfo.aspx?mid=" + Mid);
        }

        /// <summary>
        /// 获取当前Url中指定的参数的值，若该参数不存在则返回空字符串
        /// </summary>
        /// <param name="pName">参数名</param>
        /// <returns></returns>
        public string GetUrlParam(string pName)
        {
            string pValue = Request.QueryString[pName];
            if (pValue != null)
                return pValue.Trim();
            return string.Empty;
        }

        /// <summary>
        /// 把指定的object转换为string，若是null或DBNull值则返回空字符串
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public string ConvertToString(object obj)
        {
            return this.ConvertToString(obj, null);
        }

        /// <summary>
        /// 将指定的对象转换为字符串值
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="format"></param>
        /// <returns></returns>
        public string ConvertToString(object obj, string format)
        {
            if (obj == null || Convert.IsDBNull(obj))
                return String.Empty;
            if (format == null)
                return obj.ToString();
            try
            {
                if (obj is double)
                {
                    double d = (double)obj;
                    return d.ToString(format);
                }
                if (obj is decimal)
                {
                    decimal d = (decimal)obj;
                    return d.ToString(format);
                }
                if (obj is DateTime)
                {
                    DateTime d = (DateTime)obj;
                    return d.ToString(format);
                }
            }
            catch (FormatException)
            {
                throw new FormatException("数据类型转换错误，要转换的数据类型不支持指定的格式字符串！");
            }
            return obj.ToString();
        }

        /// <summary>
        /// 添加删除确认
        /// </summary>
        /// <param name="ctrl"></param>
        /// <param name="uname"></param>
        internal void AddDeleteConfirm(WebControl ctrl, string uname)
        {
            if (ctrl is Button || ctrl is LinkButton || ctrl is ImageButton)
            {
                ctrl.ToolTip = string.Format("删除该{0}", uname);
                ctrl.Attributes.Add("onclick", string.Format("return confirm(\'您确实要删除指定的{0}吗？\');", uname));
            }
        }

        /// <summary>
        /// 注册客户端Javascript脚本
        /// </summary>
        /// <param name="scriptStr">客户端Javascript脚本字符串，不包括<script>与</script>标签。</param>
        /// <param name="scriptID">脚本标识</param>
        /// <param name="isStartup">是否为启动脚本</param>
        internal void RegisterJavaScript(string scriptStr, string scriptID, bool isStartup)
        {
            StringBuilder sb = new StringBuilder(500);
            sb.Append("<script Language=\"Javascript\">");
            sb.Append(scriptStr).Append("</script>");
            if (isStartup)
            {
                if (!Page.IsStartupScriptRegistered(scriptID))
                    Page.RegisterStartupScript(scriptID, sb.ToString());
            }
            else
            {
                if (!Page.IsClientScriptBlockRegistered(scriptID))
                    Page.RegisterClientScriptBlock(scriptID, scriptStr);
            }
        }

        /// <summary>
        /// 向客户端发送Javascript脚本
        /// </summary>
        /// <param name="script"></param>
        internal void WriteJavaScript(string script, bool end)
        {
            Response.Write("<script Language=\"Javascript\">");
            Response.Write(script);
            Response.Write("</");
            Response.Write("script>");
            if (end)
                Response.End();
        }

        /// <summary>
        /// 在客户端弹出确认对话框，点击确定按钮后跳转到trueUrl，否则蹼转到falseUrl
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="okUrl">点击确定按钮后要跳转的页面，若为null则为当前页路径</param>
        /// <param name="cancelUrl">点击取消按钮后要跳转的页面，若为null则为当前页路径</param>
        internal void Confirm(string msg, string okUrl, string cancelUrl)
        {
            if (okUrl == null || okUrl.Trim().Length == 0)
                this.WriteJavaScript("if(confirm(\'" + msg + "\')) location.href=location.href;else location.href=\'" + cancelUrl + "\';", true);
            else if (cancelUrl == null || cancelUrl.Trim().Length == 0)
                this.WriteJavaScript("if(confirm(\'" + msg + "\')) location.href=\'" + okUrl + "\';else location.href=location.href;", true);
            else
                this.WriteJavaScript("if(confirm(\'" + msg + "\')) location.href=\'" + okUrl + "\';else location.href=\'" + cancelUrl + "\';", true);
        }

        /// <summary>
        /// 显示客户端提示对话框。
        /// </summary>
        /// <param name="msg"></param>
        internal void ShowMessageBox(string msg)
        {
            if (msg == null)
                return;

            WriteJavaScript("alert(\"" + EscapeJavascriptString(msg) + "\");", false);
        }
        /// <summary>
        /// 将Javascript中的特殊字符用转义符替换。
        /// </summary>
        /// <param name="jStr"></param>
        /// <returns></returns>
        internal string EscapeJavascriptString(string jStr)
        {
            string tempStr = jStr.Replace("\"", "\\\"");
            tempStr = tempStr.Replace("\'", "\\\'").Replace("\n", "\\n").Replace("\r", "\\r");
            return tempStr;
        }

        /// <summary>
        /// 弹出提示框，然后跳转到指定页
        /// </summary>
        /// <param name="msg">要弹出的提示信息</param>
        /// <param name="url">要跳转到的Url，若为空则刷新当前页</param>
        /// 修改通过设置location.href属性打开新页为用window.open()方法来打开，
        /// 以便将提示页不保存在访问历史记录中，便于用户点击后退按钮后直接返回原来的页面而未提示页面
        internal void AlertAndReturn(string msg, string url)
        {
            if (url == null)
                WriteJavaScript("alert(\"" + EscapeJavascriptString(msg) + "\");window.open(location.href,'_self',null,true);", true);
            else
                WriteJavaScript("alert(\"" + EscapeJavascriptString(msg) + "\");window.open(\"" + url + "\",'_self',null,true);", true);
        }

        /// <summary>
        /// 弹出提示框提示用户，关闭提示框后跳转到首页。
        /// </summary>
        /// <param name="msg"></param>
        internal void AlertAndReturn(string msg)
        {
            AlertAndReturn(msg, "ListInfo.aspx");
        }

        /// <summary>
        /// 弹出提示框提示用户，随后关闭当前窗口。
        /// </summary>
        /// <param name="msg"></param>
        internal void AlertAndCloseWin(string msg)
        {
            WriteJavaScript("alert(\"" + EscapeJavascriptString(msg) + "\");top.opener=null;top.close();", true);
        }


        /// <summary>
        /// 将TextBox中的值转换为int类型的数值。
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        internal int ParseIntValue(TextBox box)
        {
            try
            {
                int ivalue = 0;
                string istr = box.Text.Trim();
                if (istr != null && istr.Length > 0)
                    ivalue = int.Parse(istr);
                return ivalue;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 将TextBox中的值转换为DateTime类型的值。
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        internal DateTime ParseDateTimeValue(TextBox box)
        {
            try
            {
                DateTime dt = DateTime.MinValue;
                string dtstr = box.Text.Trim();
                if (dtstr != null && dtstr.Length > 0)
                    dt = DateTime.Parse(dtstr);
                return dt;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 将TextBox中的值转换为byte类型的数值。
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        internal byte ParseByteValue(TextBox box)
        {
            try
            {
                byte ivalue = 0;
                string istr = box.Text.Trim();
                if (istr != null && istr.Length > 0)
                    ivalue = byte.Parse(istr);
                return ivalue;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }

        /// <summary>
        /// 将TextBox中的值转换为decimal类型的数值。
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        internal decimal ParseDecimalValue(TextBox box)
        {
            if (box == null)
                return 0;
            else
            {
                decimal dValue = 0;
                string dStr = box.Text.Trim();
                try
                {
                    dValue = decimal.Parse(dStr);
                }
                catch (FormatException)
                {
                    dValue = 0;
                }
                catch
                {
                    dValue = 0;
                }
                return dValue;
            }
        }

        // <summary>
        /// 将字符串的值转换为decimal类型的数值。
        /// </summary>
        /// <param name="box"></param>
        /// <returns></returns>
        internal decimal ParseDecimalValue(string box)
        {
            if (box == null)
                return 0;
            else
            {
                decimal dValue = 0;
                string dStr = box;
                try
                {
                    dValue = decimal.Parse(dStr);
                }
                catch (FormatException)
                {
                    dValue = 0;
                }
                catch
                {
                    dValue = 0;
                }
                return dValue;
            }
        }

        /// <summary>
        /// 选定ListControl中具有指定Text或Value属性的项。
        /// </summary>
        /// <param name="ddl"></param>
        /// <param name="obj"></param>
        /// <param name="isText"></param>
        internal void SelectListItem(ListControl ddl, object obj, bool isText)
        {
            if (obj != null)
            {
                if (isText)
                {
                    if (ddl.Items.FindByText(obj.ToString()) != null)
                    {
                        ddl.SelectedIndex = -1;
                        ddl.Items.FindByText(obj.ToString()).Selected = true;
                    }
                    else
                    {
                        if (ddl.Items.Count > 0)
                            ddl.SelectedIndex = 0;
                    }
                }
                else
                {
                    if (ddl.Items.FindByValue(obj.ToString()) != null)
                    {
                        ddl.SelectedIndex = -1;
                        ddl.Items.FindByValue(obj.ToString()).Selected = true;
                    }
                    else
                    {
                        if (ddl.Items.Count > 0)
                            ddl.SelectedIndex = 0;
                    }
                }
            }
            else
                ddl.SelectedIndex = -1;
        }

        /// <summary>
        /// 从服务器端重新跳转回当前页
        /// </summary>
        internal void Refresh()
        {
            Response.Redirect(Request.RawUrl);
        }

        /// <summary>
        /// 把DateTime类型转换成短日期型,如果是MinValue则反回空字符
        /// </summary>
        /// <param name="time">DateTime</param>
        /// <returns>String</returns>
        internal string PrintDateTime(DateTime time)
        {
            return WriteDateTime(time, "d");
        }

        /// <summary>
        /// 将日期变量的值输入为字符串，当日期等于DateTime.MinValue时输入出空值
        /// </summary>
        /// <param name="dtime">要输入的日期值</param>
        /// <param name="format">日期格式字符串</param>
        /// <returns>被格式化后的日期字符串</returns>
        public string WriteDateTime(DateTime dtime, string format)
        {
            if (dtime == DateTime.MinValue)
                return string.Empty;
            return dtime.ToString(format);
        }


        /// <summary>
        /// 从当前请求的url中获取指定的int类型的参数，若该页数不存在若类型错误则提示并跳转
        /// </summary>
        /// <returns>参数值，若该参数不存在或数据类型错误则返回-1</returns>
        internal int CheckIntIDParameter()
        {
            string p = CheckStringIDParameter();
            if (p == string.Empty)
                return -1;
            else
            {
                try
                {
                    int iResult = int.Parse(p);
                    return iResult;
                }
                catch
                {
                    this.AlertAndReturn("无法显示该页：无效的参数！");
                    return -1;
                }
            }
        }


        /// <summary>
        /// 从当前请求的url中获取id字符串参数值，若该页数不存在若类型错误则提示并跳转
        /// </summary>
        /// <returns>参数值，若该参数不存在或数据类型错误则返回空字符串</returns>
        internal string CheckStringIDParameter()
        {
            string p = Request.QueryString["id"];
            if (p == null || p.Trim().Length == 0)
            {
                this.AlertAndReturn("无法显示该页：参数丢失！");
                return String.Empty;
            }
            return p.ToLower();
        }

        /// <summary>
        /// 禁用当前页上的表单元素
        internal void DisableFormElements(Control topCtrl, WebControl excludedCtrl)
        {
            foreach (Control ctrl in topCtrl.Controls)
            {
                if (ctrl is HtmlForm)
                {
                    foreach (Control sctrl in ctrl.Controls)
                    {
                        if (sctrl != excludedCtrl)
                        {
                            if (sctrl is TextBox || sctrl is ListControl || sctrl is CheckBox || sctrl is RadioButton || sctrl is Button)
                                ((WebControl)sctrl).Enabled = false;
                            else if (sctrl is ImageButton)
                            {
                                ImageButton ibtn = (ImageButton)sctrl;
                                ibtn.Enabled = false;
                                ibtn.Attributes.Add("style", "cursor:default");
                            }
                            if (!(sctrl is BaseDataList) && sctrl.HasControls())
                                DisableFormElements(sctrl, excludedCtrl);
                        }
                    }
                    break;
                }
            }
        }

        /// <summary>
        /// 禁用当前页上的表单元素
        /// </summary>
        internal void DisableFormElements()
        {
            this.DisableFormElements(this, null);
        }


        //弹出窗口显示系统意外错误信息
        internal void DisplayExceptionMessage(Exception ex)
        {
            this.ShowMessageBox(string.Format("系统出现意外错误：{0}\\n请联系系统管理员或稍后再试！", ex.Message));
        }
        /// <summary>
        /// 判断输入的内容是否是 汉字
        /// </summary>
        /// <param name="str"></param>
        /// <returns>返回是否是汉字的bool值</returns>
        internal bool IsChinese(string str)
        {
            return Regex.IsMatch(str, "^[\u4E00-\u9FA5]*$");
        }

        /// <summary>
        /// 根据生日获取年龄
        /// </summary>
        /// <param name="br">出生日期 string</param>
        /// <returns></returns>
        public string GetAgeByBirthDay(string br)
        {
            string age = "";
            if (br.Trim().Length > 0)
            {
                int y = DateTime.Now.Year - DateTime.Parse(br).Year;
                if (DateTime.Now.Month < DateTime.Parse(br).Month)
                    age = (y - 1).ToString();
                else if (DateTime.Now.Month == DateTime.Parse(br).Month)
                {
                    if (DateTime.Now.Day < DateTime.Parse(br).Day)
                        age = (y - 1).ToString();
                    else
                        age = y.ToString();
                }
                else
                    age = y.ToString();

            }
            return age;
        }
        /// <summary>
        /// 绑定下拉框 默认值为 ---请选择---
        /// </summary>
        /// <param name="ddl">DropDownList 对象</param>
        /// <param name="tableName">数据源表名</param>
        /// <param name="txtName">显示信息DataField</param>
        /// <param name="valName">值信息 DataField</param>
        /// <param name="strWhe">查询条件</param>
        public static void BindDLL(DropDownList ddl, string tableName, string txtName, string valName, string strWhe)
        {
            ddl.Items.Clear();
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select " + txtName + "," + valName + " FROM " + tableName + " where  1=1 " + strWhe + "");
            {
                DataRow dr = dt.NewRow();
                dr[txtName] = "全部";
                dr[valName] = 0;
                dt.Rows.InsertAt(dr, 0);

                if (dt != null && dt.Rows.Count > 0)
                {
                    ddl.DataSource = dt;
                    ddl.DataTextField = txtName;
                    ddl.DataValueField = valName;
                    ddl.DataBind();
                }
                ddl.SelectedValue = "0";
            }
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <param name="ddl">DropDownList 对象</param>
        /// <param name="tableName">数据源表名</param>
        /// <param name="txtName">显示信息DataField</param>
        /// <param name="valName">值信息 DataField</param>
        /// <param name="strWhe">查询条件</param>
        public static void BindDLLDef(DropDownList ddl, string tableName, string txtName, string valName, string strWhe)
        {
            ddl.Items.Clear();
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select " + txtName + "," + valName + " FROM " + tableName + " where  1=1 " + strWhe + "");
            {
                //DataRow dr = dt.NewRow();
                //dr[txtName] = "---请选择---";
                //dr[valName] = 0;
                //dt.Rows.InsertAt(dr, 0);

                if (dt != null && dt.Rows.Count > 0)
                {
                    ddl.DataSource = dt;
                    ddl.DataTextField = txtName;
                    ddl.DataValueField = valName;
                    ddl.DataBind();
                }
            }
        }
        /// <summary>
        /// 绑定下拉框
        /// </summary>
        /// <param name="ddl">HtmlSelect 对象</param>
        /// <param name="tableName">数据源表名</param>
        /// <param name="txtName">显示信息DataField</param>
        /// <param name="valName">值信息 DataField</param>
        /// <param name="strWhe">查询条件</param>
        public static void BindDLL(HtmlSelect ddl, string tableName, string txtName, string valName, string strWhe)
        {
            ddl.Items.Clear();
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select " + txtName + "," + valName + " FROM " + tableName + " where  1=1 " + strWhe + "");
            {
                DataRow dr = dt.NewRow();
                dr[txtName] = "全部";
                dr[valName] = 0;
                dt.Rows.InsertAt(dr, 0);

                if (dt != null && dt.Rows.Count > 0)
                {
                    ddl.DataSource = dt;
                    ddl.DataTextField = txtName;
                    ddl.DataValueField = valName;
                    ddl.DataBind();
                }
                ddl.Value = "0";
            }
        }
        /// <summary>
        /// 绑定分页数据
        /// </summary>
        /// <param name="pg">AspNetPager 控件</param>
        /// <param name="dt">显示数据的DataTable</param>
        /// <param name="rptCtr">Repeater 控件</param>
        /// <param name="rcount">查询结果总条数</param>
        public void SetNetPagerHtml(AspNetPager pgCtr, DataTable dt, Repeater rptCtr, int rcount)
        {
            pgCtr.PageSize = WebPageSize;
            pgCtr.RecordCount = rcount;
            rptCtr.DataSource = dt;
            rptCtr.DataBind();
            WebPageIndex = pgCtr.CurrentPageIndex;
            SetNetPageStyle(pgCtr);
        }
        /// <summary>
        /// 设置分页样式显示的内容及格式
        /// </summary>
        /// <param name="pgCtr">ASPNETPAGE对象</param>
        public void SetNetPageStyle(AspNetPager pgCtr)
        {
            pgCtr.CustomInfoHTML = "共 <font color=red><b>" + pgCtr.PageCount.ToString() + " </b></font>页<font color=red><b> ";
            pgCtr.CustomInfoHTML += pgCtr.RecordCount.ToString() + " </b></font>条记录 ";
            pgCtr.CustomInfoHTML += "&nbsp; 当前第 <font color=red><b>" + pgCtr.CurrentPageIndex.ToString() + " </b></font>页";
        }

        public void InsertLog(string strContent, int logType)
        {
            Model.Sys.Sys_Log log = new Model.Sys.Sys_Log();
            log.UserID = LoggedUser.ID;
            log.LogContent = strContent;
            string type = "";
            switch (logType)
            {
                case 1:
                    type = "登录日志";
                    break;
                case 2:
                    type = "操作日志";
                    break;
                default:
                    break;
            }
            log.LogType = type;
            new DAL.Sys.Sys_LogData().Add(log);
        }
        public void InsertLog(string strContent)
        {
            Model.Sys.Sys_Log log = new Model.Sys.Sys_Log();
            log.UserID = LoggedUser.ID;
            log.LogContent = strContent;
            string type = "";
            log.LogType = type;
            new DAL.Sys.Sys_LogData().Add(log);
        }
        #endregion

        #region GET/SET aspx页面 服务器控件值
        /// <summary>
        /// 获取aspx页面 服务器控件值，返回实体类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="page"></param>
        /// <returns></returns>
        public static T GetWebControls<T>(Control page)
        {
            Hashtable ht = GetWebControls(page);
            T model = Activator.CreateInstance<T>();
            Type type = model.GetType();
            //遍历每一个属性
            foreach (PropertyInfo prop in type.GetProperties())
            {
                try
                {
                    object value = ht[prop.Name];
                    if (prop.PropertyType.ToString() == "System.Nullable`1[System.DateTime]")
                    {
                        value = CommonHelper.ToDateTime(value);
                    }
                    prop.SetValue(model, DbReader.HackType(value, prop.PropertyType), null);
                }
                catch
                { }
            }
            return model;
        }

        /// <summary>
        /// 获取aspx页面 服务器控件值，返回哈希表
        /// </summary>
        /// <param name="page"></param>
        /// <returns></returns>
        public static Hashtable GetWebControls(Control page)
        {
            Hashtable ht = new Hashtable();
            int size = HttpContext.Current.Request.Params.Count;
            for (int i = 0; i < size; i++)
            {
                string id = HttpContext.Current.Request.Params.GetKey(i);
                Control control = page.FindControl(id);
                if (control == null) continue;
                control = page.FindControl(id);
                if (control is HtmlInputText)
                {
                    HtmlInputText txt = (HtmlInputText)control;
                    ht[txt.ID] = txt.Value.Trim();
                }
                if (control is HiddenField)
                {
                    HiddenField txt = (HiddenField)control;
                    ht[txt.ID] = txt.Value.Trim();
                }
                if (control is HtmlSelect)
                {
                    HtmlSelect txt = (HtmlSelect)control;
                    ht[txt.ID] = txt.Value.Trim();
                }
                if (control is HtmlInputHidden)
                {
                    HtmlInputHidden txt = (HtmlInputHidden)control;
                    ht[txt.ID] = txt.Value.Trim();
                }
                if (control is HtmlInputPassword)
                {
                    HtmlInputPassword txt = (HtmlInputPassword)control;
                    ht[txt.ID] = txt.Value.Trim();
                }
                if (control is HtmlInputCheckBox)
                {
                    HtmlInputCheckBox chk = (HtmlInputCheckBox)control;
                    ht[chk.ID] = chk.Checked ? 1 : 0;
                }
                if (control is HtmlTextArea)
                {
                    HtmlTextArea area = (HtmlTextArea)control;
                    ht[area.ID] = area.Value.Trim();
                }
            }
            return ht;
        }

        /// <summary>
        /// 实体类给服务器控件赋值
        /// </summary>
        /// <param name="page"></param>
        /// <param name="entity">实体类</param>
        public static void SetWebControls<T>(Control page, T entity)
        {
            SetWebControls(page, HashtableHelper.GetModelToHashtable(entity));
        }
        /// <summary>
        /// 创建哈希表给服务器控件赋值
        /// </summary>
        /// <param name="page"></param>
        /// <param name="ht"></param>
        public static void SetWebControls(Control page, Hashtable ht)
        {
            if (ht.Count != 0)
            {
                int size = ht.Keys.Count;
                foreach (string key in ht.Keys)
                {
                    object val = ht[key];
                    if (val != null)
                    {
                        Control control = page.FindControl(key);
                        if (control == null) continue;
                        if (control is HtmlInputText)
                        {
                            HtmlInputText txt = (HtmlInputText)control;
                            txt.Value = val.ToString().Trim();
                        }
                        if (control is HtmlSelect)
                        {
                            HtmlSelect txt = (HtmlSelect)control;
                            txt.Value = val.ToString().Trim();
                        }
                        if (control is HtmlInputHidden)
                        {
                            HtmlInputHidden txt = (HtmlInputHidden)control;
                            txt.Value = val.ToString().Trim();
                        }
                        if (control is HtmlInputPassword)
                        {
                            HtmlInputPassword txt = (HtmlInputPassword)control;
                            txt.Value = val.ToString().Trim();
                        }
                        if (control is Label)
                        {
                            Label txt = (Label)control;
                            txt.Text = val.ToString().Trim();
                        }
                        if (control is HtmlInputCheckBox)
                        {
                            HtmlInputCheckBox chk = (HtmlInputCheckBox)control;
                            chk.Checked = CommonHelper.GetInt(val) == 1 ? true : false;
                        }
                        if (control is HtmlTextArea)
                        {
                            HtmlTextArea area = (HtmlTextArea)control;
                            area.Value = val.ToString().Trim();
                        }
                    }
                }
            }
        }
        #endregion


        /// <summary>
        /// List页面字符串截取                                                                                  
        /// </summary>
        /// <param name="dataStr">被截取对象</param>
        /// <param name="maxLength">最大长度</param>
        /// <returns></returns>
        public string GetAStr(string dataStr, int maxLength)
        {
            if (dataStr.Length > maxLength)
            {
                return "<a href='#' title='" + dataStr + "'>" + dataStr.Substring(0, maxLength) + "......</a>";
            }
            return dataStr;
        }

        /// <summary>
        /// 添加审批信息
        /// </summary>
        /// <param name="aType">内容类型 0=采购需求 1=采购合同 2=卡片订货单 3=卡片验收入库 4=卡片需求单 5=半成品/成品入库 6=卡片发放需求 7=半成品/成品卡申领  8=半成品/成品卡出库 9=半成品/成品卡发放 10=白卡出库 11=未售问题卡回收 12=报废入库 13=卡片退货</param>
        /// <param name="aId">内容id</param>
        public void InsertAppInfo(int aType, string aId)
        {
            OracleParameter[] parameters = {
                    new OracleParameter("vINFOTYPE", OracleType.Number),
                    new OracleParameter("vINFOID", OracleType.VarChar),
                    new OracleParameter("vADDUSER", OracleType.VarChar),
                    new OracleParameter("vmid", OracleType.Number),
                    new OracleParameter("varOut", OracleType.VarChar,50)};
            parameters[0].Value = aType;
            parameters[1].Value = aId;
            parameters[2].Value = LoggedUser.ID;
            parameters[3].Value = Mid;
            parameters[4].Direction = ParameterDirection.Output;

            DbHelperSQL.RunProcedure("P_ApprovalInfo_Add", parameters, parameters[4]);

        }
        public string GetAppStatusName(string statusCode)
        {
            //0 未提交 1 待审核 2 审核中 3 驳回 4 审核不通过 5审核通过
            string result = "";
            switch (statusCode)
            {
                default:
                    result = "<span style='color:red;'>未提交</span>";
                    break;
                case "1":
                    result = "待审核";
                    break;
                case "2":
                    result = "审核中";
                    break;
                case "3":
                    result = "驳回";
                    break;
                case "4":
                    result = "审核不通过";
                    break;
                case "5":
                    result = "审核通过";
                    break;
            }
            return result;
        }

        /// <summary>
        /// 根据状态获取图片状态
        /// </summary>
        /// <param name="isSubmit">  0 未提交 1 待审核 2 审核中 3 驳回 4 审核不通过 5审核通过</param>
        /// <param name="titleName">显示的标题</param>
        /// <returns></returns>
        public string GetStatusInfo(int isSubmit, string titleName)
        {
            StringBuilder sbStr = new StringBuilder();
            sbStr.Append("<div style='width: 100%; text-align: center; font-size: 22px; font-weight: bold;");
            sbStr.Append(" vertical-align: middle; padding-top:15px;");
            if (isSubmit >= 0)
            {
                sbStr.Append("background:url(../../../images/AccStatus_" + isSubmit + ".png) no-repeat center right;");
            }
            sbStr.Append("padding-bottom:15px;'>");
            sbStr.Append(titleName + "</div>");
            return sbStr.ToString();
        }

        /// <summary>
        /// 获取最大编号
        /// </summary>
        /// <param name="tName">表名</param>
        /// <param name="strNO">编号字段名称</param>
        /// <param name="strWhere">查询条件</param>
        /// <returns>最大编号</returns>
        public string GetMAXNO(string tName, string strNO, string strWhere)
        {
            string result = "";
            DataTable dt = CardLogistics.DAL.DbHelperSQL.GetQueryResult(" select * from (select " + strNO + " from " + tName + " where 1=1 " + strWhere + "  order by  to_number(REGEXP_REPLACE(replace(" + strNO + ",'-',''),'[a-zA-Z/:.]','')) desc) where rownum=1");
            if (dt != null && dt.Rows.Count > 0)
            {
                try
                {
                    //获取编号
                    string sno = dt.Rows[0][0].ToString();
                    //// 取出字符串中所有的英文字母 
                    //string code = Regex.Replace(sno, "[0-9]", "", RegexOptions.IgnoreCase);
                    //// 取出字符串中所有的数字  
                    //string num = Regex.Replace(sno, "[a-z]", "", RegexOptions.IgnoreCase);
                    //if (string.IsNullOrEmpty(num))
                    //    num = "0";
                    //Int64 addNum = Convert.ToInt64(num) + 1;
                    //string newNum = (addNum).ToString().PadLeft(num.Length, '0');

                    string code = "";
                    int addNum = 0;
                    if (sno != "")
                    {
                        code = sno.Substring(0, sno.Length - 1);//获取除去最后一个字母之前的编号
                        string num = sno.Substring(sno.Length - 1, 1);//获取最后一位编号
                        addNum = Convert.ToInt32(num) + 1;
                    }
                    result = code + addNum;
                }
                catch
                {
                    return "";
                }
            }
            return result;
        }
        /// <summary>
        /// 获取最新单据编号
        /// </summary>
        /// <param name="billName">单据名称（采购需求、采购合同、卡片订货单、订货台账）</param>
        /// <param name="kind">操作类型（0 查询，1获取编号并修改最后记录的编号）</param>
        /// <returns></returns>
        public string GetBillNumber(string billName)
        {
            string billNumber = "";//返回单据号
            try
            {
                string strSql = "select Fun_GetBillNumber('" + billName + "',0) from dual ";
                DataTable dt = DbHelperSQL.GetQueryResult(strSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    billNumber = dt.Rows[0][0].ToString();
                }
            }
            catch
            { }
            return billNumber;
        }
        /// <summary>
        /// 改变当前最大单号
        /// </summary>
        /// <param name="billName"></param>
        public void ChgBillNumber(string billName)
        {
            try
            {
                string strSql = "select Fun_GetBillNumber('" + billName + "',1) from dual ";
                DataTable dt = DbHelperSQL.GetQueryResult(strSql);
            }
            catch
            { }
        }

        /// <summary>
        /// 通过供应商ID得到最大的开始箱号
        /// </summary>
        /// <param name="supId">供应商ID</param>
        /// <returns></returns>
        public string GetBoxStartNo(string supId)
        {
            string boxNumber = "";//返回箱号
            try
            {
                string strSql = "select Fun_GetBoxNo('" + supId + "') from dual ";
                DataTable dt = DbHelperSQL.GetQueryResult(strSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    boxNumber = dt.Rows[0][0].ToString();
                }
            }
            catch
            { }
            return boxNumber;
        }

        /// <summary>
        /// 通过卡片类型Id得到最大的起始卡号
        /// </summary>
        /// <param name="cardTypeId">卡片类型Id</param>
        /// <returns></returns>
        public string GetMaxStartCardNo(string cardTypeId)
        {
            string startCardNo = "";//返回起始卡号
            try
            {
                string strSql = "select Fun_StartCode('" + cardTypeId + "') from dual ";
                DataTable dt = DbHelperSQL.GetQueryResult(strSql);
                if (dt != null && dt.Rows.Count > 0)
                {
                    startCardNo = dt.Rows[0][0].ToString();
                }
            }
            catch
            { }
            return startCardNo;
        }

        #region 金额转为大写金额
        public static string ShowMoney(string LowerMoney)
        {
            // 保留两位小数 123.489→123.49　　123.4→123.4
            LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();
            if (LowerMoney.IndexOf(".") > 0)
            {
                if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2)
                {
                    LowerMoney = LowerMoney + "0";
                }
            }
            else
            {
                LowerMoney = LowerMoney + ".00";
            }
            string strLower = LowerMoney;
            int iTemp = 1;
            string strUpart = string.Empty;
            string strUpper = "";
            while (iTemp <= strLower.Length)
            {
                switch (strLower.Substring(strLower.Length - iTemp, 1))
                {
                    case ".":
                        strUpart = "";
                        break;
                    case "0":
                        strUpart = "零";
                        break;
                    case "1":
                        strUpart = "壹";
                        break;
                    case "2":
                        strUpart = "贰";
                        break;
                    case "3":
                        strUpart = "叁";
                        break;
                    case "4":
                        strUpart = "肆";
                        break;
                    case "5":
                        strUpart = "伍";
                        break;
                    case "6":
                        strUpart = "陆";
                        break;
                    case "7":
                        strUpart = "柒";
                        break;
                    case "8":
                        strUpart = "捌";
                        break;
                    case "9":
                        strUpart = "玖";
                        break;
                }
                strUpper += strUpart;
                iTemp = iTemp + 1;
            }
            return strUpper;
        }
        /// <summary>
        /// 金额转换
        /// </summary>
        /// <param name="LowerMoney"></param>
        /// <returns></returns>
        public static List<string> MoneyToLine(string LowerMoney)
        {
            List<string> _lsit = new List<string>();
            LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();
            if (LowerMoney.IndexOf(".") > 0)
            {
                if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2)
                {
                    LowerMoney = LowerMoney + "0";
                }
            }
            else
            {
                LowerMoney = LowerMoney + ".00";
            }
            string strLower = LowerMoney.Replace(".", "");
            int iTemp = 1;
            string strRet = " ";
            while (iTemp <= strLower.Length)
            {
                string str = strLower.Substring(strLower.Length - iTemp, 1);
                _lsit.Add(str);
                iTemp = iTemp + 1;
            }
            return _lsit;
        }
        /// <summary>
        /// 金额转为大写金额
        /// </summary>
        /// <param name="LowerMoney"></param>
        /// <returns></returns>
        public static string MoneyToChinese(string LowerMoney)
        {
            string functionReturnValue = null;
            bool IsNegative = false; // 是否是负数

            if (LowerMoney.Trim().Substring(0, 1) == "-")
            {
                // 是负数则先转为正数

                LowerMoney = LowerMoney.Trim().Remove(0, 1);
                IsNegative = true;
            }
            string strLower = null;
            string strUpart = null;
            string strUpper = null;
            int iTemp = 0;
            // 保留两位小数 123.489→123.49　　123.4→123.4
            LowerMoney = Math.Round(double.Parse(LowerMoney), 2).ToString();
            if (LowerMoney.IndexOf(".") > 0)
            {
                if (LowerMoney.IndexOf(".") == LowerMoney.Length - 2)
                {
                    LowerMoney = LowerMoney + "0";
                }
            }
            else
            {
                LowerMoney = LowerMoney + ".00";
            }
            strLower = LowerMoney;
            iTemp = 1;
            strUpper = "";
            while (iTemp <= strLower.Length)
            {
                switch (strLower.Substring(strLower.Length - iTemp, 1))
                {
                    case ".":
                        strUpart = "张";
                        break;
                    case "0":
                        strUpart = "零";
                        break;
                    case "1":
                        strUpart = "壹";
                        break;
                    case "2":
                        strUpart = "贰";
                        break;
                    case "3":
                        strUpart = "叁";
                        break;
                    case "4":
                        strUpart = "肆";
                        break;
                    case "5":
                        strUpart = "伍";
                        break;
                    case "6":
                        strUpart = "陆";
                        break;
                    case "7":
                        strUpart = "柒";
                        break;
                    case "8":
                        strUpart = "捌";
                        break;
                    case "9":
                        strUpart = "玖";
                        break;
                }

                switch (iTemp)
                {
                    case 1:
                        strUpart = strUpart + "分";
                        break;
                    case 2:
                        strUpart = strUpart + "角";
                        break;
                    case 3:
                        strUpart = strUpart + "";
                        break;
                    case 4:
                        strUpart = strUpart + "";
                        break;
                    case 5:
                        strUpart = strUpart + "拾";
                        break;
                    case 6:
                        strUpart = strUpart + "佰";
                        break;
                    case 7:
                        strUpart = strUpart + "仟";
                        break;
                    case 8:
                        strUpart = strUpart + "万";
                        break;
                    case 9:
                        strUpart = strUpart + "拾";
                        break;
                    case 10:
                        strUpart = strUpart + "佰";
                        break;
                    case 11:
                        strUpart = strUpart + "仟";
                        break;
                    case 12:
                        strUpart = strUpart + "亿";
                        break;
                    case 13:
                        strUpart = strUpart + "拾";
                        break;
                    case 14:
                        strUpart = strUpart + "佰";
                        break;
                    case 15:
                        strUpart = strUpart + "仟";
                        break;
                    case 16:
                        strUpart = strUpart + "万";
                        break;
                    default:
                        strUpart = strUpart + "";
                        break;
                }

                strUpper = strUpart + strUpper;
                iTemp = iTemp + 1;
            }

            strUpper = strUpper.Replace("零拾", "零");
            strUpper = strUpper.Replace("零佰", "零");
            strUpper = strUpper.Replace("零仟", "零");
            strUpper = strUpper.Replace("零零零", "零");
            strUpper = strUpper.Replace("零零", "零");
            strUpper = strUpper.Replace("零角零分", "整");
            strUpper = strUpper.Replace("零分", "整");
            strUpper = strUpper.Replace("零角", "零");
            strUpper = strUpper.Replace("零亿零万零张", "亿张");
            strUpper = strUpper.Replace("亿零万零张", "亿张");
            strUpper = strUpper.Replace("零亿零万", "亿");
            strUpper = strUpper.Replace("零万零张", "万张");
            strUpper = strUpper.Replace("零亿", "亿");
            strUpper = strUpper.Replace("零万", "万");
            strUpper = strUpper.Replace("零张", "张");
            strUpper = strUpper.Replace("零零", "零");

            // 对壹张以下的金额的处理

            if (strUpper.Substring(0, 1) == "张")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "零")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "角")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "分")
            {
                strUpper = strUpper.Substring(1, strUpper.Length - 1);
            }
            if (strUpper.Substring(0, 1) == "整")
            {
                strUpper = "零张整";
            }
            functionReturnValue = strUpper;

            if (IsNegative == true)
            {
                return "负" + functionReturnValue;
            }
            else
            {
                return functionReturnValue;
            }
        }
        /// <summary>
        /// 将数字转换为汉字
        /// </summary>
        /// <param name="strLower"></param>
        /// <returns></returns>
        public static string NumChangChinese(string strLower)
        {
            string strUpart = "";
            switch (strLower)
            {
                case "0":
                    strUpart = "零";
                    break;
                case "1":
                    strUpart = "壹";
                    break;
                case "2":
                    strUpart = "贰";
                    break;
                case "3":
                    strUpart = "叁";
                    break;
                case "4":
                    strUpart = "肆";
                    break;
                case "5":
                    strUpart = "伍";
                    break;
                case "6":
                    strUpart = "陆";
                    break;
                case "7":
                    strUpart = "柒";
                    break;
                case "8":
                    strUpart = "捌";
                    break;
                case "9":
                    strUpart = "玖";
                    break;
            }
            return strUpart;
        }
        #endregion

        /// <summary>
        /// 导出报表
        /// </summary>
        /// <param name="strFileName">文件名</param>
        public void ExportExcel(string strFileName, HtmlGenericControl dCon)
        {
            strFileName = System.Web.HttpUtility.UrlEncode(strFileName, System.Text.Encoding.UTF8);
            System.Web.HttpContext.Current.Response.Clear();
            System.Web.HttpContext.Current.Response.Buffer = true;
            System.Web.HttpContext.Current.Response.Charset = "UTF-8";
            System.Web.HttpContext.Current.Response.AppendHeader("Content-Disposition", "online; filename=" + strFileName + ".xls");
            //System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.GetEncoding("UTF-8");
            System.Web.HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default;
            System.Web.HttpContext.Current.Response.ContentType = "application/ms-excel";
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("zh-CN", true);
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            dCon.RenderControl(oHtmlTextWriter);
            System.Web.HttpContext.Current.Response.Write(oStringWriter.ToString().Replace("<td", "<td STYLE='FONT-SIZE:14px;text-align: center;height: 40px;'")
                                                          .Replace("#B4CDEB", "#000000"));
            System.Web.HttpContext.Current.Response.Buffer = false;
            System.Web.HttpContext.Current.Response.End();
        }

        #region 下载文件
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="filePath">文件路径</param>
        /// <param name="fileName">下载后的文件名</param>
        protected void DownLoad(string filePath, string fileName)
        {
            fileName = System.Web.HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8);
            FileInfo fi = new FileInfo(filePath);
            HttpResponse contextResponse = HttpContext.Current.Response;
            contextResponse.Clear();
            contextResponse.Buffer = true;
            contextResponse.Charset = "UTF-8"; //设置类型 
            contextResponse.AppendHeader("Content-Disposition", String.Format("attachment;filename={0}", fileName)); //定义输出文件和文件名 
            contextResponse.AppendHeader("Content-Length", fi.Length.ToString());
            contextResponse.ContentEncoding = Encoding.Default;
            contextResponse.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。 
            contextResponse.WriteFile(fi.FullName);
            contextResponse.Flush();
            contextResponse.End();
        }
        #endregion

        #region 读取Excel数据()
        /// <summary>
        /// 读取Excel数据
        /// </summary>
        /// 第一种方法：传统方法，采用OleDB读取EXCEL文件,优点：写法简单，缺点：服务器必须安有此组件才能用，不推荐使用
        /// <param name="filepath">Excel服务器路径</param>
        /// <param name="tableName">Excel表名称</param>
        /// <returns></returns>
        protected DataSet GetDataFromExcel(string filepath, string tableName)
        {
            string strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties='Excel 8.0;HDR=YES;IMEX=1'";
            OleDbConnection ExcelConn = new OleDbConnection(strCon);
            try
            {
                string strCom = string.Format("SELECT * FROM [Sheet1$]");
                ExcelConn.Open();
                OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, ExcelConn);
                DataSet ds = new DataSet();
                myCommand.Fill(ds, "[" + tableName + "$]");
                ExcelConn.Close();
                ShowMessageBox(ds.Tables[0].ToString());
                return ds;
            }
            catch (Exception ex)
            {
                ShowMessageBox(ex.Message);
                ExcelConn.Close();
                return null;
            }
        }
        #endregion


        //config中配置的上传的Excel路径
        //static object basePath = "~/MainPage/File/CheckUpFile/";// ConfigurationManager.AppSettings["FilePath"];
        #region 读取Excel文件
        /// <summary>
        /// 读取Excel文件到table中 适应于Office2003的版本
        /// </summary>
        /// 第二种方法：用第三方组件：NPOI组件,推荐使用此方法(http://blog.csdn.net/lybwwp/article/details/20133983)
        /// <param name="filePath">excel文件路径</param>
        /// <returns></returns>
        public static DataTable ReadExcel(object basePath, string fileName)
        {
            DataTable dt = new DataTable();
            string filePath = "";
            if (basePath != null)
            {
                filePath = HostingEnvironment.MapPath((basePath.ToString() + fileName));
                dt = ImportExcelFile(filePath);
            }
            //文件是否存在
            if (System.IO.File.Exists(filePath))
            {

            }
            return dt;
        }
        public static DataTable ImportExcelFile(string filePath)
        {
            HSSFWorkbook hssfworkbook;
            #region//初始化信息
            try
            {
                using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read))
                {
                    hssfworkbook = new HSSFWorkbook(file);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            #endregion

            NPOI.SS.UserModel.ISheet sheet = hssfworkbook.GetSheetAt(0);
            System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
            DataTable dt = new DataTable();
            rows.MoveNext();
            HSSFRow row = (HSSFRow)rows.Current;
            for (int j = 0; j < (sheet.GetRow(0).LastCellNum); j++)
            {
                //dt.Columns.Add(Convert.ToChar(((int)'A') + j).ToString());
                //将第一列作为列表头
                dt.Columns.Add(row.GetCell(j).ToString());
            }
            while (rows.MoveNext())
            {
                row = (HSSFRow)rows.Current;
                DataRow dr = dt.NewRow();
                for (int i = 0; i < row.LastCellNum; i++)
                {
                    NPOI.SS.UserModel.ICell cell = row.GetCell(i);
                    if (cell == null)
                    {
                        dr[i] = null;
                    }
                    else
                    {
                        dr[i] = cell.ToString();
                    }
                }
                dt.Rows.Add(dr);
            }
            return dt;
        }
        #endregion    


        /// <summary>
        /// 绑定审核状态
        /// </summary>
        /// <param name="ddl">DropDownList 对象</param>
        public void BindDLL(DropDownList ddl)
        {
            ddl.Items.Clear();
            DataTable dt = new DataTable();
            dt.Columns.Add("valName");
            dt.Columns.Add("txtName");
            DataRow dr = dt.NewRow();
            dr = dt.NewRow();
            dr["valName"] = -1;
            dr["txtName"] = "全部";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 0;
            dr["txtName"] = "未提交";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 1;
            dr["txtName"] = "待审核";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 2;
            dr["txtName"] = "审核中";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 3;
            dr["txtName"] = "驳回";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 4;
            dr["txtName"] = "审核不通过";
            dt.Rows.Add(dr);

            dr = dt.NewRow();
            dr["valName"] = 5;
            dr["txtName"] = "审核通过";
            dt.Rows.Add(dr);

            ddl.DataSource = dt;
            ddl.DataTextField = "txtName";
            ddl.DataValueField = "valName";
            ddl.DataBind();
        }
    }
}
